<div class="row">
    <div class="col-md-12 widget-module">
        <div class="box-widget">
            <div class="widget-head clearfix">
                <h4 class="pull-left"><?php echo $this->translate('create voucher'); ?></h4>
            </div>
            
            <div class="widget-container">
                <div class="widget-block">
                    <div class="widget-content">
                        <form id="usergroup" method="post" class="form-horizontal form-box">
                            <div class="form-group <?php echo $this->classError['voucher_code']; ?>">
                                <label class="col-lg-2 control-label"><?php echo $this->translate('voucher code'); ?></label>
                                <div class="col-lg-6">
                                    <input class="form-control" type="text" value="<?php echo $this->data['voucher_code']; ?>" name="voucher_code" class="form-control" placeholder="<?php echo $this->translate('voucher code'); ?>" />
                                    <?php echo $this->messageError['voucher_code']; ?>
                                </div>
                            </div>
                            
                            <div class="form-group <?php echo $this->classError['description']; ?>">
                                <label class="col-lg-2 control-label"><?php echo $this->translate('description'); ?></label>
                                <div class="col-lg-6">
                                    <input class="form-control" type="text" value="<?php echo $this->data['description']; ?>" name="description" class="form-control" placeholder="<?php echo $this->translate('description'); ?>" />
                                    <?php echo $this->messageError['description']; ?>
                                </div>
                            </div>
                            
                            <div class="form-group <?php echo $this->classError['order_value']; ?>">
                                <label class="col-lg-2 control-label"><?php echo $this->translate('order value'); ?></label>
                                <div class="col-lg-6">
                                    <input class="form-control"  id="order_value"type="text" value="<?php echo $this->data['order_value']; ?>" class="form-control" placeholder="<?php echo $this->translate('order value'); ?>" />
                                    <input type="hidden" name="order_value" value="" />
                                    <?php echo $this->messageError['order_value']; ?>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label class="col-lg-2 control-label"><?php echo $this->translate('type'); ?></label>
                                <div class="col-lg-6">
                                    <select name="type" class="form-control">
                                        <option value="0"><?php echo $this->translate('fixed'); ?></option>
                                        <option <?php if(isset($this->data['type']) && $this->data['type'] == 1) echo 'selected="selected"'; ?> value="1"><?php echo $this->translate('percent'); ?></option>
                                    </select>
                                </div>
                            </div>
                            
                            <div class="form-group <?php echo $this->classError['value']; ?>">
                                <label class="col-lg-2 control-label"><?php echo $this->translate('value'); ?></label>
                                <div class="col-lg-6">
                                    <input class="form-control"  id="value"type="text" value="<?php echo $this->data['value']; ?>" class="form-control" placeholder="<?php echo $this->translate('value'); ?>" />
                                    <input type="hidden" name="value" value="" />
                                    <?php echo $this->messageError['value']; ?>
                                </div>
                            </div>
                            
                            <div class="form-group <?php echo $this->classError['quantity']; ?>">
                                <label class="col-lg-2 control-label"><?php echo $this->translate('quantity'); ?></label>
                                <div class="col-lg-6">
                                    <input class="form-control"  id="quantity"type="text" value="<?php echo $this->data['quantity']; ?>" class="form-control" placeholder="<?php echo $this->translate('quantity'); ?>" />
                                    <input type="hidden" name="quantity" value="" />
                                    <?php echo $this->messageError['quantity']; ?>
                                </div>
                            </div>
                            
                            <div class="form-group  <?php echo $this->classError['time']; ?>">
                                <label class="col-lg-2 control-label" for="reservation"><?php echo $this->translate('time'); ?></label>
                                <div class="col-lg-6">
                                    <input id="daterange" value="<?php echo $this->data['time']; ?>" readonly="" class="form-control" type="text" name="time" placeholder="<?php echo $this->translate('time'); ?>" />
                                    <?php echo $this->messageError['time']; ?>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label class="col-lg-2 control-label"><?php echo $this->translate('status'); ?></label>
                                <div class="col-lg-4">
                                    <div class="checkbox">
                                        <label>
                                            <input <?php if($this->data['status']) echo 'checked="checked"'; ?> type="checkbox" name="status" value="1" />
                                            <?php echo $this->translate('active'); ?>
                                        </label>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label class="col-lg-2 control-label">&nbsp;</label>
                                <div class="col-lg-4">
                                    <div class="form-actions">
                                        <button id="save" type="submit" class="btn btn-primary">
                                            <i class="icon-save"></i>
                                            <?php echo $this->translate('save'); ?>
                                        </button>
                                        <button id="cancel" type="button" class="btn">
                                            <i class="icon-cancel-circle-2"></i>
                                            <?php echo $this->translate('cancel'); ?>
                                        </button>
                                    </div>
                                </div>
                            </div> 
                            <?php if(isset($this->data['id']) && $this->data['id'] > 0): ?>
                            <input type="hidden" name="id" value="<?php echo $this->data['id']; ?>" />
                            <input type="hidden" name="save" value="1" />
                            <?php endif; ?>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
$("#cancel").click(function(){
    window.location = "<?php echo $this->url(array('module' => 'admin', 'controller' => 'voucher', 'action' => 'index'), null, true); ?>";
});

$("#save").click(function(){
    var value = $("#value").unmask();
    $("input[name='value']").val(value);
    
    var order_value = $("#order_value").unmask();
    $("input[name='order_value']").val(order_value);
    
    var quantity = $("#quantity").unmask();
    $("input[name='quantity']").val(quantity);
});

$(function() {
    var today = new Date();
    var nextYear = '12/31/' + (today.getFullYear() + 1);
    
    $('#daterange').daterangepicker(
        {
            minDate: today,
            maxDate: nextYear,
            showDropdowns: true,
        }
    );
    
    $("input[id='order_value']").priceFormat({
        prefix: '',
        clearPrefix: true,
        thousandsSeparator: '.',
        centsLimit: 0
    });
    
    $("input[id='quantity']").priceFormat({
        prefix: '',
        clearPrefix: true,
        thousandsSeparator: '.',
        centsLimit: 0
    });
    
    $("input[id='value']").priceFormat({
        prefix: '',
        clearPrefix: true,
        thousandsSeparator: '.',
        centsLimit: 0
    });
});
</script>